import axios from 'axios'
import {Message} from 'element-ui'

// 创建axios实例/console/api

console.log(process.env.VUE_APP_TARGET);
const service = axios.create({
    baseURL: '/console/api/v2', // api的base_url
    timeout: 15000 // 请求超时时间
});
// request拦截器
service.interceptors.request.use(config => {
    return config
}, error => {
    console.log(error);// for debug
    Promise.reject(error)
});

// respone拦截器
service.interceptors.response.use(
    response => {
        /**
         * code为非200是抛错 可结合自己业务进行修改
         */
        const res = response.data;
        if (res.status != 200) {
            Message({
                message: res.message,
                type: 'error',
                duration: 3 * 1000
            });
            return Promise.reject('error')
        } else {
            return response.data
        }
    },
    error => {
        Message({
            message: error.message,
            type: 'error',
            duration: 3 * 1000
        });
        return Promise.reject(error)
    }
);
export default service
